<script language=JavaScript src='../inv/scripts/innovaeditor.js'></script>

<?
$path="../upload";
$pathdb="../upload";

if (isset($_POST['butSave'])) {
	$id=$_POST['ddContent'];
	$content= addslashes($_POST['txtcontent']);

	$ret=CheckUpload($_FILES['txtImage'],".jpg;.gif;.bmp;.png;.swf;",500*1024,0);
	if ($ret!='') $err.="Hình không &#273;úng &#273;&#7883;nh d&#7841;ng, ho&#7863;c l&#7899;n h&#417;n kích th&#432;&#7899;c gi&#7899;i h&#7841;n (500KB)<br>";		
		
	if ($err=="") 
	{
		if (mysql_query("update contents set contents_content='".$content."' where contents_id='".$id."'",$con)) {
			if ($_POST['chkClear']=='')
			{
				$sqlUpdateField = "";
				$extsmall=GetFileExtention($_FILES['txtImage']['name']);
				if (MakeUpload($_FILES['txtImage'],"$path/content_s$id$extsmall"))
				{
					$sqlUpdateField = " contents_image='$pathdb/content_s$id$extsmall' ";
					@chmod("$path/content_s$id$extsmall",0766);
				}
			}
			else 
				$sqlUpdateField = " contents_image='' ";
				
			if($sqlUpdateField)
			{
				$sqlUpdate = "update contents set $sqlUpdateField where contents_id='".$id."'";
				mysql_query($sqlUpdate,$con);
			}
		}	
		else {
			$err =  "<p align=center class='err'>Không th&#7875; c&#7853;p nh&#7853;t</p>";
		}
		if ($err=='') echo "<p align=center class='err'>&#272;ã c&#7853;p nh&#7853;t thành công</p>";
	  	//if ($err=='') echo '<script>window.location="index.php?act=content&id='.$_REQUEST['id'].'&code=1"/script>';
	 }
	if($err!="") echo "<p align=center class='err'>".$err."</p>"; 
}

$id=1;
if ($_REQUEST['id']!='') $id=$_REQUEST['id'];
$cont=GetContentInfo($id);
?>

<form method="POST" name="frmSubmit" enctype="multipart/form-data" action="index.php" style="margin-top: 0; margin-bottom: 0">
<input type="hidden" name="act" value="<? echo $_REQUEST['act']; ?>">
<input type="hidden" name="id" value="<? echo $_REQUEST['id']; ?>">

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#0069A8" width="100%" id="AutoNumber1">
  <tr>
    <td width="45%" class="title" align="center" height="20">S&#7917;a &#273;&#7893;i / C&#7853;p nh&#7853;t 
	: N&#7897;i dung</td>
  </tr>
  <tr>
    <td width="45%">
    <table border="0" cellpadding="2" bordercolor="#111111" width="100%" id="AutoNumber2" cellspacing="0">
<? if ($cont['contents_image']!='') { ?>
      <tr>
        <td width="99%" class="smallfont" colspan="4" align="center">

		<img border="0" src="<? echo $cont['contents_image']; ?>">
        </td>
      </tr>
<? } ?>
      <tr>
        <td width="15%" class="smallfont">
        <p align="right">Ch&#7885;n</td>
        <td width="1%" class="smallfont" align="center">
        <font color="#FF0000">*</font></td>
        <td width="4%" class="smallfont">
		<select size="1" name="ddContent">
<?
$list=GetListContent();
$id=$_REQUEST['id'];
foreach ($list as $c)
{
	if ($id=="") $id=$c[0];
	if ($c[0]!==$_REQUEST['id'])
		echo '<option value="'.$c[0].'">'.$c[1].'</option>';
	else
		echo '<option selected value="'.$c[0].'">'.$c[1].'</option>';
}
?>
		</select></td>
        <td width="79%" class="smallfont">
		<input type="button" value="Chuy&#7875;n" name="B1" class="button" onclick="javascript:window.location='./?act=content&id='+ddContent.value"></td>
      </tr>
 <!--     <tr>
        <td width="15%" class="smallfont" align="right">
        Hình &#7843;nh</td>
        <td width="1%" class="smallfont" align="center">&nbsp;
        </td>
        <td width="83%" class="smallfont" colspan="2">
		<INPUT TYPE="file" NAME="txtImage" CLASS=textbox size="34"><input type="checkbox" name="chkClear" value="ON">Xóa 
		b&#7887; hình</td>
      </tr> -->

      <tr>
        <td width="15%" class="smallfont" align="right">
        N&#7897;i dung</td>
        <td width="1%" class="smallfont" align="center">&nbsp;
        </td>
        <td width="83%" class="smallfont" colspan="2">
			<textarea id="txtcontent" name="txtcontent" rows=4 cols=30><? echo $cont['contents_content']; ?></textarea>
			<script> //STEP 2: Replace the textarea (txtContent)
			var oEdit1 = new InnovaEditor("oEdit1");
			oEdit1.arrStyle=[["BODY",false,"","font-family:Tahoma,Arial,Helvetica;font-size:10pt"]];
			oEdit1.width="100%";//You can also use %, for example: oEdit1.width="100%"
			oEdit1.height=350;		
			oEdit1.cmdAssetManager = "modalDialogShow('/inv/assetmanager/assetmanager.php',640,465)"; //Command to open the Asset Manager add-on.
			oEdit1.REPLACE("txtcontent");//Specify the id of the textarea here
			</script>				
		</td>
      </tr>

      <tr>
        <td width="15%" class="smallfont">
		<p align="right">
		<INPUT onclick="submitForm()" TYPE="submit" NAME="butSave" VALUE="C&#7853;p nh&#7853;t" CLASS=button>&nbsp;</td>
        <td width="1%" class="smallfont" align="center">&nbsp;
		</td>
        <td width="83%" class="smallfont" colspan="2"><p align="left">&nbsp;<INPUT TYPE="reset" CLASS=button value="Nh&#7853;p l&#7841;i"></td>
      </tr>
    </table>
    </td>
  </tr>
  </table>
</form>